package mysqlCnnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

/**
 * This class make a report to client. 
 * @author G15
 */
public class Reports extends ConnectionTOmysql 
{
	private Connection connection;
	
	/**
	 * This is the default constructor
	 * @throws IlegalMySQLPasswordORUserNameException 
	 */
	public Reports() throws IlegalMySQLPasswordORUserNameException
	{
		super();
		this.connection = super.getConnection();
	}
	
	public String getResponseReport(long activeID)
	{
		Statement stmt;
		String str = "";
		String sqlmsg = ("SELECT cID3, COUNT(*) FROM purchases p WHERE ActiveID3 ="+activeID+" GROUP BY cID3;");
		try
		{
			stmt = connection.createStatement();
			ResultSet rs = stmt.executeQuery(sqlmsg);
			if (rs.next())
			{
				str = str + "Campaign: "+ rs.getLong(1)+" Number of purchases "+rs.getLong(2)+"\n";				
			}
			sqlmsg = ("SELECT response FROM delay WHERE ActiveID2 ="+activeID+";");
			rs = stmt.executeQuery(sqlmsg);
			str = str+"All response:\n";
			while(rs.next())
			{
				str = str+rs.getString(1)+"\n";				
			}			
			rs.close();
			return str;
		} catch (SQLException e)
		{
			return null;
		}	
		
	}
	
	/**
	 * This method make customer report.
	 * @return String
	 */
	public String customerReport()
	{
		Statement stmt;
		String str = "";
		String sqlmsg = ("SELECT * FROM clients ORDER BY importance;");
		try
		{
			stmt = connection.createStatement();
			ResultSet rs = stmt.executeQuery(sqlmsg);
			while(rs.next())
			{
				str = str+ String.format("%-10s %-10s %-10s %-10s %-10s %-10s \n",
						rs.getString(1), rs.getString(2), rs.getString(3),
				rs.getString(4),rs.getString(5),rs.getString(6));				
			}			
			rs.close();
			return str;
		} catch (SQLException e)
		{
			return null;
		}	
	}


}
